const config = require('../../common/config');
const util = require('../../utils/util');

Page({
    data: {
        shopCollects:[],
        hasShopCollect:false
    },
    onLoad: function () {
        wx.setNavigationBarTitle({
            title: '收藏'
        })

        this.loadCollectShop()
    },
    loadCollectShop: function () {
        var that = this;
        wx.showLoading({
            title: '加载中..',
            icon: 'loading',
            duration: config.TIME_OUT,
            mask: true
        })

        wx.request({
            url: config.COMMPT_REQPATH,
            header: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            method: 'POST',
            data: {
                accessToken: '',
                refreshToken: '',
                serviceName: 'collectService',
                methodName: 'getUserCollectList',
                reqData: JSON.stringify({
                    userId: wx.getStorageSync(config.USER_ID),
                    type: '01'
                })
            },
            success: function (res) {
                var resultData = res.data;
                if (resultData.code == 1) {
                    var collectShopList = resultData.data.collectShopList;
                    util.debug(resultData);
                    that.setData({
                        shopCollects:collectShopList,
                    })
                    if(collectShopList.length>0){
                        that.setData({
                            hasShopCollect:true
                        })
                    }
                } else {
                    util.debug('获取用户收藏信息失败：');
                    util.debug(resultData);
                    that.setData({
                        shopCollects:[],
                        hasShopCollect:false
                    })
                }
            },
            fail: function (e) {
                util.debug(e.errMsg);
                that.setData({
                    shopCollects:[],
                    hasShopCollect:false
                })
            },
            complete: function () {
                wx.hideLoading();
            }
        })
    },
    toShopDetail:function (e) {
        wx.redirectTo({
            url: e.currentTarget.dataset.url
        })
    }
})